""" 
Copyright 2009 Texas A&M University
 
Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
this file except in compliance with the License. You may obtain a copy of the 
License at

http://www.apache.org/licenses/LICENSE-2.0
  
Unless required by applicable law or agreed to in writing, software distributed 
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
CONDITIONS OF ANY KIND, either express or implied. See the License for the 
specific language governing permissions and limitations under the License.
"""

from zope.interface import Interface, implements
from zope.schema import Bool, TextLine, Int, Float, List, Dict, Object
from zope.i18nmessageid import MessageFactory

from plone.theme.interfaces import IDefaultPloneLayer

from meercat.ui.plone.content.interfaces import IMeercatSearch



_ = MessageFactory('meercat.ui.plone')

class IMeercatBrowserLayer(IDefaultPloneLayer):
    """Marker interface that defines a Zope 3 skin layer for this product.
    """

class IMeercatSchema(Interface):
    enabled = Bool(title=_(u'Enabled'), default=False,
        description=_(u'Check this to enable the meercat interface.'))
    
    solr_enabled = Bool(title=_(u'SOLR Enabled'), default=False,
        description=_(u'Check this to enable the SOLR meercat interface.'))
    
    solr_url = TextLine(title=_(u'SOLR Base URL'),
        description=_(u'The base URL of the Solr instance to be used.'))
    
    solr_ssl_key_file = TextLine(title=_(u'SSL Key File'),
        description=_(u'The SSL Key file for authentication on the Solr server'),
        required=False)
    
    solr_ssl_cert_file = TextLine(title=_(u'SSL Cert File'),
        description=_(u'The SSL Cert file for authentication on the Solr server'),
        required=False)
    
    solr_timeout = Float(title=_(u'SOLR Timeout'),
        description=_(u'Number of seconds after which a search request will '
                       'time out. Set to "0" to disable timeouts.'))
    
    solr_default_parameters = Dict(title=_(u'Default query parameters'),
        description=_(u'Specify key/value pairs for default query parameters'),
        key_type=TextLine(),
        value_type=TextLine(),
        required=False)
    
    solr_forced_parameters = Dict(title=_(u'Forced query parameters'),
        description=_(u'Specifiy key/value pairs for forced query parameters'),
        key_type=TextLine(),
        value_type=TextLine(),
        required=False)
    
    rest_enabled = Bool(title=_(u'REST Enabled'), default=False,
        description=_(u'Check this to enable the REST meercat interface.'))
    
    rest_url = TextLine(title=_(u'REST Base URL'),
        description=_(u'The base URL of the REST interface'))
    
    rest_timeout = Float(title=_(u'REST Timeout'),
        description=_(u'Number of seconds after which a request will time out. '
                       'Set to "0" to disable timeouts.'))

class IMeercatConnectionConfig(IMeercatSchema):
    """ utility to hold the connection configuration for the solr server """

class IMeercatConnectionManager(Interface):
    """ a thread-local connection manager for solr """
    
    def enable(self):
        """ Enable the meercat UI """
    
    def disable(self):
        """ Disable the meercat UI """
    
    def configureSolr(self, **kwargs):
        """ configure the solr connection """
    
    def configureRest(self, **kwargs):
        """ configure the rest connection """
    
    def closeSolrConnection(self):
        """ close the current solr connection, if any """
    
    def getSolrConnection(self):
        """ returns an existing solr connection or opens one """
    
    def closeRestConnection(self):
        """ close the current rest connection, if any """
    
    def getRestConnection(self):
        """ return an existing rest connection or opens one and returns it """
    
    def getIdentifierField(self):
        """ return the primary identifier field from SOLR """
    
    def getSolrVersion(self):
        """ return the version of SOLR from the configured server """

class IMeercatSearchResults(Interface):
    """ a sol(a)r brain, i.e. a data container for search results """


class IMeercatResource(Interface):
    """ marker interface for pluggable brain wrapper classes, providing
        additional helper methods like `getURL` etc """

class IMeercatInstance(Interface):
    """ """

